<template>
  <div class="app-container">
    <el-form :inline="true" :model="lineForm">
      <el-form-item label="线路名称">
        <el-input v-model="lineForm.lineName" :clearable="true"/>
      </el-form-item>
      <el-form-item label="出发站点">
        <el-select v-model="lineForm.startAddress" placeholder="请选择" value="">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="目的站点">
        <el-select v-model="lineForm.endAddress" placeholder="请选择" value="">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="onSearch">搜索</el-button>
        <el-button type="danger" icon="el-icon-plus" @click="onAdd">新增</el-button>
        <el-button type="success" icon="el-icon-refresh" @click="onRefresh">刷新</el-button>
        <el-button icon="el-icon-delete" @click="onCancel">清除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        type="index"
        width="50"/>
      <el-table-column
        prop="date"
        label="创建时间"/>
      <el-table-column
        prop="name"
        label="线路编码"/>
      <el-table-column
        prop="address"
        label="线路名称"/>
      <el-table-column
        prop="date"
        label="出发站点"/>
      <el-table-column
        prop="name"
        label="目的站点"/>
      <el-table-column
        fixed="right"
        label="操作"
        width="250">
        <template slot-scope="scope">
          <el-button type="primary" size="small" icon="el-icon-edit" @click="onEdit">编辑</el-button>
          <el-button type="danger" size="small" icon="el-icon-delete" @click="onDelete">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog :visible.sync="addDrivingLine" title="新增线路">
      <el-form :model="addLine" :inline="true">
        <el-form-item :label-width="addDrivingLineWidth" label="线路编码">
          <el-input v-model="addLine.num" autocomplete="off"/>
        </el-form-item>
        <el-form-item :label-width="addDrivingLineWidth" label="线路名称">
          <el-input v-model="addLine.name" autocomplete="off"/>
        </el-form-item>
        <el-form-item :label-width="addDrivingLineWidth" label="出发站点">
          <el-select v-model="addLine.start" value="">
            <el-option label="区域一" value="shanghai"/>
            <el-option label="区域二" value="beijing"/>
          </el-select>
        </el-form-item>
        <el-form-item :label-width="addDrivingLineWidth" label="到达站点">
          <el-select v-model="addLine.end" value="">
            <el-option label="区域一" value="shanghai"/>
            <el-option label="区域二" value="beijing"/>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addDrivingLine = false">取 消</el-button>
        <el-button type="primary" @click="addDrivingLine = false">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="editDrivingLine" title="新增线路">
      <el-form :model="editLine" :inline="true">
        <el-form-item :label-width="addDrivingLineWidth" label="线路编码">
          <el-input v-model="editLine.num" autocomplete="off"/>
        </el-form-item>
        <el-form-item :label-width="addDrivingLineWidth" label="线路名称">
          <el-input v-model="editLine.name" autocomplete="off"/>
        </el-form-item>
        <el-form-item :label-width="addDrivingLineWidth" label="出发站点">
          <el-select v-model="editLine.start" value="">
            <el-option label="区域一" value="shanghai"/>
            <el-option label="区域二" value="beijing"/>
          </el-select>
        </el-form-item>
        <el-form-item :label-width="addDrivingLineWidth" label="到达站点">
          <el-select v-model="editLine.end" value="">
            <el-option label="区域一" value="shanghai"/>
            <el-option label="区域二" value="beijing"/>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDrivingLine = false">取 消</el-button>
        <el-button type="primary" @click="editDrivingLine = false">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
export default {
  name: 'Index',
  data() {
    return {
      lineForm: {
        lineName: '',
        startAddress: '',
        endAddress: ''
      },
      options: [{
        value: '选项1',
        label: '黄金糕'
      }],
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }],
      addDrivingLineWidth: '120px',
      addDrivingLine: false,
      editDrivingLine: false,
      addLine: {
        num: '',
        name: '',
        start: '',
        end: ''
      },
      editLine: {
        num: '',
        name: '',
        start: '',
        end: ''
      }
    }
  },
  methods: {
    onSearch() {
      console.log('onSearch')
    },
    onRefresh() {
      console.log('onSearch')
    },
    onCancel() {
      this.lineForm.lineName = ''
      this.lineForm.startAddress = ''
      this.lineForm.endAddress = ''
    },
    onAdd() {
      this.addDrivingLine = true
    },
    onEdit() {
      this.editDrivingLine = true
    },
    onDelete() {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }

  }
}
</script>

<style scoped>

</style>
